package org.example.examfx02.controller;

import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import org.example.examfx02.entity.Student;
import org.example.examfx02.tool.SystemData;

import java.util.List;

public class ShowViewController {
    static String strId = TeaViewController.id;
    static String strType = TeaViewController.type;
    SystemData sys = SystemData.getInstance();
    List<Student> list = null;
    @FXML
    TableView<Student> table;
    @FXML
    TableColumn<Student,String> id;
    @FXML
    TableColumn<Student,String> name;
    @FXML
    TableColumn<Student,String> myClass;
    public void initialize(){
        if("必修".equals(strType)){
            list = sys.getUserGroup().getStudents();
        }else{
            list = sys.getSelectCourceStudent(strId);
        }
        name.setCellValueFactory(new PropertyValueFactory<>("username"));
        myClass.setCellValueFactory(new PropertyValueFactory<>("myClass"));
        id.setCellValueFactory(new PropertyValueFactory<>("id"));
        // 设置单元格工厂，使内容居中
        id.setCellFactory(MainViewController.createCenteredCellFactory());
        name.setCellFactory(MainViewController.createCenteredCellFactory());
        myClass.setCellFactory(MainViewController.createCenteredCellFactory());
        table.setItems(FXCollections.observableArrayList(list));
    }
}
